﻿#pragma once

#include <vector>
#include <stdexcept>
#include <map>

#ifndef ASSERT
#ifdef DEBUG
#include <cassert>
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif
#endif

// 只支持 utf-8 编码, 所以使用 char, std::string

namespace xml
{
	class ParseError : public std::runtime_error
	{
	public:
		ParseError(const std::string &msg) : std::runtime_error(msg) {}
		ParseError(const char *msg) : std::runtime_error(msg) {}
	};

	enum class ElemType
	{
		Normal,
		Text
	};

	struct Element;
	using Elements = std::vector<Element>;
	using Attrs = std::map<std::string, std::string>;

	struct Element
	{
		// Text 内容直接塞进 name 里面了
		std::string name;
		Attrs attrs;
		Elements subs;
		ElemType type = ElemType::Normal;
	};

	bool operator==(const Element &l, const Element &r);

	Elements ParseFile(const std::string &fileName);
	Elements ParseString(const std::string &content);
}
